package com.shareinfo.auto.main;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.shareinfo.auto.service.AutoBuildService;
import com.shareinfo.auto.vo.ConfigureDatabase;
import com.shareinfo.auto.vo.ConfigureInit;
import com.shareinfo.auto.vo.ConfigureTemplate;
import com.shareinfo.auto.vo.ResultInfo;
import com.shareinfo.base.common.file.FileUtil;

/**
 * 
 * @author Administrator
 *
 */
public class Template2BaseSmk {
	

	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("spring/applicationContext-*.xml");
		AutoBuildService autoBuildService = (AutoBuildService) context.getBean("autoBuildService");
		ResultInfo resultInfo =null;
		
		String[][] table={
			{"","","","",""}	
			,{"com.shareinfo.adminManage.auto","AutoDb","auto_db","数据库","/adminManage/sys"}
			,{"com.shareinfo.adminManage.auto","AutoDbClass","auto_db_class","数据库表分类","/adminManage/sys"}
			,{"com.shareinfo.adminManage.auto","AutoDbTable","auto_db_table","数据库表","/adminManage/sys"}
			,{"com.shareinfo.adminManage.auto","AutoDbTableField","auto_db_table_field","数据库表字段","/adminManage/sys"}
		};
		ConfigureInit conf = new ConfigureInit();
		conf.setConfigureTemplate(getConfigureTemplate());
		conf.setConfigureDatabase(getConfigureDatabase());
		
		for (int i = 0; i < table.length; i++) {
			if("".equals(table[i][0]))
				continue;
			conf.setPackageName(table[i][0]);
			conf.setClassName(table[i][1]);
			conf.setTableName(table[i][2].toUpperCase());
			conf.setComments(table[i][3]);
			conf.setUrlPath(table[i][4]);
			
			resultInfo = autoBuildService.run(conf);
			System.out.println(resultInfo);
		}	

	}

	// 获取配置模板
	public static ConfigureTemplate getConfigureTemplate() {
		ConfigureTemplate configureTemplate = new ConfigureTemplate();
		configureTemplate.setTemplateId("2");
		configureTemplate.setPath("H:/jobCode/git/hpAutoBuild/auto/src/main/webapp/sysTemplate/2");
		configureTemplate.setOutPath("D:/output");
		if(true){
			new FileUtil().deleteDirectory(configureTemplate.getOutPath());
		}
		return configureTemplate;
	}

	// 获取模板数据库
	public static ConfigureDatabase getConfigureDatabase() {
		ConfigureDatabase configureDatabase = new ConfigureDatabase();
		configureDatabase.setDriver("com.mysql.jdbc.Driver");
		configureDatabase.setUrl("jdbc:mysql://localhost:3306/smk?useUnicode=true&characterEncoding=UTF-8");
		configureDatabase.setUsername("root");
		configureDatabase.setPassword("root");
		configureDatabase.setSchema(null);
		configureDatabase.setCatalog(null);
		return configureDatabase;
	}
}
